/**
 * Copyright (c) 2009 blurredVision
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 
 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#ifndef __MODEL_IMODELBASERENDERER_H__
#define __MODEL_IMODELBASERENDERER_H__

#pragma once

#include "IShaderEffect.h"

namespace model {

/**
 *  A material for the model.
 */
struct sComplexMaterial {
	IShaderEffect *pEffect0;
	ITexture      *pTexture0;
	ITexture      *pTexture1;
	ITexture      *pTexture2;

	bool isTAMat;	///< Indicates if this material contains texture atlas informations

	SHADERHANDLE hDiffuseTex;
	SHADERHANDLE hNormalTex;
	SHADERHANDLE hAdditionalTex;
	SHADERHANDLE hLight;

	SHADERHANDLE hDepthTech;
	SHADERHANDLE hDefaultTech;
	SHADERHANDLE hTATech;

	unsigned int uiVisibleMeshes;

	std::vector<IMesh*> m_lLinkedMeshes;
	std::vector<IMesh*> m_lLinkedTranspMeshes;

	const bool operator==(const sComplexMaterial &mat) const
	{
		return ((pEffect0 == mat.pEffect0) && (pTexture0 == mat.pTexture0) && (pTexture1 == mat.pTexture1) && (pTexture2 == mat.pTexture2));
	}
};


/**
 *  A static non-animated model. This replaces directx::Model
 */
class DLL_EXPORT IModelBaseRenderer
{
public:
	/// Draws all visible meshes in the world grouped by sComplexMaterial
	static void DrawByMaterial(math::Matrix4 *postMat = 0, bool drawTransparent = false);

	/// Draws all the visible meshes as they come from the mesh list
	static void DrawByMesh(math::Matrix4 *postMat = 0, bool drawTransparent = false);

	static void ResetMaterialCount();
	static void ClearMaterials();

	typedef std::list<sComplexMaterial> mat_list;
	typedef std::list<model::IMesh*>    mesh_list;

	/// Adds a mesh to the list of known meshes
	static void AddMesh(IMesh* mesh);

	/// Removes a mesh from the list of known meshes
	static void RemoveMesh(IMesh* mesh);

protected:
	IModelBaseRenderer(void);
	virtual ~IModelBaseRenderer(void);

	static mat_list  s_lMaterials;
	static mesh_list s_lMeshes;
};

} // namespace

#endif
